package com.module.admin.tts.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.module.admin.BaseController;
import com.ms.client.task.api.pojo.TaskJob;
import com.ms.client.task.api.pojo.TaskJobLog;
import com.ms.client.task.api.service.ApiTaskJobLogService;
import com.ms.client.task.api.service.ApiTaskJobService;
import com.ms.client.task.api.service.ApiTaskProjectService;
import com.ms.msclient.MsClientResponse;
import com.system.comm.model.KvEntity;
import com.system.comm.model.Page;

/**
 * task_project的Controller
 * @author yuejing
 * @date 2015-03-30 14:07:28
 * @version V1.0.0
 */
@Controller
public class TtsTaskJobLogController extends BaseController {

	@Autowired
	private ApiTaskProjectService apiTaskProjectService;
	@Autowired
	private ApiTaskJobService apiTaskJobService;
	@Autowired
	private ApiTaskJobLogService apiTaskJobLogService;
	
	/**
	 * 跳转到管理页
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/ttsTaskJobLog/f-view/manager")
	public String manger(HttpServletRequest request, ModelMap modelMap) {
		List<KvEntity> projects = apiTaskProjectService.findAll().getBody();
		modelMap.put("projects", projects);
		return "admin/tts/task/jobLog-manager";
	}

	@RequestMapping(value = "/ttsTaskJobLog/f-view/look")
	public String edit(HttpServletRequest request, ModelMap modelMap, Integer id, Integer projectid) {
		if(id != null) {
			TaskJobLog taskJobLog = apiTaskJobLogService.get(id).getBody();
			Integer jobid = taskJobLog.getJobid();//FrameMapUtil.getInteger(taskJobLog, "jobid");
			TaskJob taskJob = apiTaskJobService.get(jobid).getBody();
			modelMap.put("taskJobLog", taskJobLog);
			modelMap.put("taskJob", taskJob);
		}
		return "admin/tts/task/jobLog-look";
	}

	@RequestMapping(value = "/ttsTaskJobLog/f-json/pageQuery")
	@ResponseBody
	public void pageQuery(HttpServletRequest request, HttpServletResponse response, TaskJobLog taskJobLog) {
		MsClientResponse<Page<TaskJobLog>> frame = apiTaskJobLogService.pageQuery(taskJobLog);
		writerJson(response, frame);
	}
}